// Copyright (C) Kumo inc. and its affiliates.
// Author: Jeff.li lijippy@163.com
// All rights reserved.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program.  If not, see <https://www.gnu.org/licenses/>.
//


#include <pybind11/pybind11.h>
#include <pybind11/stl.h>

#include <pollux/python/file/PyFile.h>
#include <pollux/python/init/PyInit.h>

namespace py = pybind11;

PYBIND11_MODULE(file, m) {
  using namespace kumo;

  pollux::py::initializePolluxMemory();
  pollux::py::registerAllResources();

  // Need types for the get_schema() output.
  py::module::import("pypollux.type");

  // File wrapper abstraction.
  py::class_<pollux::py::PyFile>(m, "File")
      .def(
          py::init<const std::string&, const std::string&>(),
          py::arg("path"),
          py::arg("format_str"),
          py::doc(R"(
        Constructs a File object given a path and a file format string.

        Args:
          path: The file or directory path.
          aliases: A string containing the lowercase name of the format.
      )"))
      .def("__eq__", &pollux::py::PyFile::equals, py::doc(R"(
        Returns if two PyFiles are the same.
      )"))
      .def("__str__", &pollux::py::PyFile::toString, py::doc(R"(
        Returns a short and recursive description of the file.
      )"))
      .def("get_schema", &pollux::py::PyFile::getSchema, py::doc(R"(
        Returns the schema from a given file. This function will open and
        read metadata from the file using the corresponding file reader.
      )"));

  m.def("PARQUET", &pollux::py::PyFile::createParquet);
  m.def("DWRF", &pollux::py::PyFile::createDwrf);
  m.def("NIMBLE", &pollux::py::PyFile::createNimble);
  m.def("ORC", &pollux::py::PyFile::createOrc);
  m.def("JSON", &pollux::py::PyFile::createJson);
  m.def("TEXT", &pollux::py::PyFile::createText);
}
